package priv.yiyuan.example.design.chain;

/**
 * @author YiYuan
 * @data 2025/10/11
 * @apoNote
 */
public class MemberLevelDiscountHandler extends DiscountHandler {

    public MemberLevelDiscountHandler(DiscountStrategy strategy) {
        super(strategy);
    }

    @Override
    public void handleDiscount(Order order) {
        DiscountStrategy currentStrategy = null;

        if (order.getMemberLevel() == 1) {
            currentStrategy = new VipMemberDiscountStrategy();
        }
        else if (order.getMemberLevel() == 2) {
            currentStrategy = new SuperVipMemberDiscountStrategy();
        }
        if (currentStrategy != null) {
            double discount = currentStrategy.calculateDiscount(order);
            if (discount > 0) {
                order.setFinalPrice(order.getFinalPrice() - discount);
                System.out.println("当前订单最终价格变为: " + String.format("%.2f", order.getFinalPrice()) + "元。");
            }
        }

        if (nextHandler != null) {
            nextHandler.handleDiscount(order);
        }
    }
}
